﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.Script.Services;
using CallBox.BL;
using CallBox.Entity;

namespace CallBox
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             *  String sType = clsEncryption.Decrypt(Request.QueryString["ex"]);
                    if (sType.Equals("Expire"))
             */
        }
        public void Verify(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Username.Text) && !String.IsNullOrEmpty(password.Text))
            {

                clsMobile objMObile = clsMobileBL.Intancia.Validate(Username.Text, password.Text);
                if (objMObile != null)
                {
                    Session["User"] = objMObile;
                    Response.Redirect("~/Private/Home/default.aspx");

                }
                else
                {
                    Alert("Datos de Movil no existen.");
                }



                // Deserialize
                /* clsPerson obj = clsPersonRule.Intancia.GetPersonByPassANDUser(Username.Text, password.Text);

                 if (obj != null)
                 {
                     BaseSession.Instance.SsPerson = obj;
                     Response.Redirect("~/Private/Home/Home.aspx");
                 }
                 else
                 {
                     Alert("Credenciales no existen.");
                 }*/
            }
            else
            {
                Alert("Debe ingresar datos de su cuenta.");
            }


        }
        public void Alert(string message)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "alerta", @"<script type='text/javascript'>jAlert('" + message + "', 'Alert');</script>", false);
        }
        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public static String Validate(String user, String pass)
        {
            string sJSON = "";
            try
            {
                if (!String.IsNullOrEmpty(user) && !String.IsNullOrEmpty(pass))
                {
                    // Int32 ID = Convert.ToInt32(clsEncryption.Decrypt(id));
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    // Deserialize
                    /*clsPerson obj = clsPersonRule.Intancia.GetPersonByPassANDUser(user, pass);

                    if (obj != null)
                    {
                        sJSON = serializer.Serialize(obj);
                    }
                    else
                    {
                        sJSON = "Credenciales no existen.";
                    }*/
                }
                else
                {
                    sJSON = "Credenciales no existen.";
                }


            }
            catch (Exception)
            {
                sJSON = "Credenciales no existen.";
            }

            return sJSON;
        }
        [WebMethod]
        public static String ListarPerson(String user, String pass)
        {

            string sJSON = "";
         /*   List<clsPerson> lst = new List<clsPerson>();

            lst = clsPersonRule.Intancia.GetPerson();
            if (lst != null)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                sJSON = serializer.Serialize(lst);

            }*/
            return sJSON;
        }
    }
}